package u1project.client;

import java.util.Scanner;

import u1project.common.Request;
import u1project.common.Response;

public class ClientMain {
	private static ClientSocket client = new ClientSocket();
	private static Scanner in = new Scanner(System.in);

	public static void login() {
		System.out.println("请输入用户名和密码：");
		Request req = new Request("login");
		req.put("name", in.next());
		req.put("pass", in.next());
		Response resp = client.send(req);
		if (resp.isSucess()) {
			download();
		} else {
			System.out.println("登录失败：" + resp.getMsg());
			/// login();
		}
	}

	public static void download() {

		Request r = new Request("download");
		System.out.println("请输入文件名");
		String name1 = in.next();
		r.put("filename", name1);
		Response resp = client.send(r);
		if (resp.isSucess()) {
			read();
		} else {
			System.out.println("下载失败：" + resp.getMsg());
		}
	}

	public static void read() {
		System.out.println("没有实现");
	}

	public static void main(String[] args) {
		client.start();
		int choice = 0;
		while (true) {
			System.out.println("1:login,2:reg，3：上传文件，4：下载文件，9退出");
			choice = in.nextInt();
			if (choice == 1) {
				login();
			} else if (choice == 9) {
				break;
			}
		}
		client.close();
	}

}
